﻿#include <iostream>
#include <string>

using namespace std;

int operation(string s);

int main()
{
	string s;
	cin >> s;
	int new_answer = operation(s);
	int answer = 0;
	while (answer != new_answer)
	{
		answer = new_answer;
		new_answer = operation(to_string(answer));
	}
	cout << answer;
}

int operation(string s)
{
	int s_length = s.length();
	int result = 0;
	for (int i = 0; i < s_length; i++) {
		result += s[i] - '0';
	}
	return result;
}